package com.iims.flowable.flow.vo.resp;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.flowable.engine.history.HistoricProcessInstance;

import java.util.Date;

/**
 * 我的任务
 *
 * @author fanpei
 * @date 2021/6/15 20:07
 */
@Data
@ApiModel("我关联的流程任务")
public class FlowMyProcessInstanceDto {

    @ApiModelProperty("发起时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date startTime;

    @ApiModelProperty("完成时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date finishTime;

    @ApiModelProperty("持续时长")
    private String duration;


    @ApiModelProperty("完成状态")
    private String completeStatus;

    //流程信息
    @ApiModelProperty("流程实例Id")
    private String processInstanceId;

    @ApiModelProperty("流程任务名称")
    private String processName;

    //@ApiModelProperty("流程分类")
    //private String category;

    @ApiModelProperty("流程部署编号")
    private String processDeployId;

    @ApiModelProperty("流程ID")
    private String processDefinitionId;

    @ApiModelProperty("流程key")
    private String processDefinitionKey;

    @ApiModelProperty("流程定义内置使用版本")
    private int processDefinitionVersion;

    @ApiModelProperty("业务key")
    private String businessKey;

    //region 额外信息

    @ApiModelProperty("启动流程节点id")
    private String startActivityId;

    @ApiModelProperty("父流程实例id")
    private String superProcessInstanceId;

    @ApiModelProperty(value = "租户id", hidden = true)
    protected String tenantId;

    //endregion 额外信息


    //region 方法区

    public void copyHistoricProcessInstance(HistoricProcessInstance hisIns) {
        this.setProcessInstanceId(hisIns.getId());
        this.setProcessName(hisIns.getName());
        this.setProcessDefinitionId(hisIns.getProcessDefinitionId());
        this.setProcessDefinitionKey(hisIns.getProcessDefinitionKey());
        this.setBusinessKey(hisIns.getBusinessKey());
        this.setStartTime(hisIns.getStartTime());
        this.setFinishTime(hisIns.getEndTime());
        this.setDuration(FlowFiledUtils.caclDuration(hisIns.getStartTime(), hisIns.getEndTime()));
        this.setCompleteStatus(null == hisIns.getEndTime() ? "进行中" : "已完成");

        this.setStartActivityId(hisIns.getStartActivityId());
        this.setSuperProcessInstanceId(hisIns.getSuperProcessInstanceId());
        this.setTenantId(hisIns.getTenantId());
        this.setProcessDeployId(hisIns.getDeploymentId());
        this.setProcessDefinitionVersion(hisIns.getProcessDefinitionVersion());

    }

    //endregion 方法区
}
